package com.tianqu.tms.www.cardect.action;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.DectCodes;
import com.tianqu.tms.entity.TmsDetectPic;
import com.tianqu.tms.www.cardect.actionform.TisDetectSeniorActionForm;
import com.tianqu.tms.www.cardect.viewhelper.CarSeniorDetectInputViewHelper;
import com.tianqu.tms.www.cardect.viewhelper.CarSeniorDetectViewHelper;
/**
 * 高级检测录入检测信息Action
 * 
 * @author tianshifu
 *
 */
public class CarWCSeniorDetectInputAction extends TmsAction {
	private Logger logger = Logger.getLogger(CarWCSeniorDetectInputAction.class);//log
	private static final String DETECT_POSITION = "detect_position";//检测位置，标识哪个button提交
	private static final String SENIOR_DETECT_INPUT_DATA = "senior_detect_input_data";//检测录入信息
	public static final String CARSERIAL = "carSerial";
	public static final String POSITION = "position";//页面传过来的检测位置
	private static final String IMGLIST = "imgList";//用于存放图片对象的list

	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");		
		//每次都进入到这个Action中 进入到这个页面的时候需要传过来一个位置ID 根据位置ID对对应的选项进行添加
		//每次都需要判断是否为空，为空的话过掉
		//从form中获取页面表单
		TisDetectSeniorActionForm seniorDetectForm = (TisDetectSeniorActionForm)form;
		
		CarSeniorDetectInputViewHelper view = new CarSeniorDetectInputViewHelper();//返回的时候需要冲uc中取值
		
		String position = "";
		
		String actionForward = "";//点击不同的按钮跳转到不同的路径
		
		if(uc.getAttribute(DETECT_POSITION)==null)
		{
			position = request.getParameter(POSITION);
		}
		else{
			
			position = (String)uc.getAttribute(DETECT_POSITION);
		}
		//修改时页面已经有值，所以需要将页面的值拆分，set到inputViewhelp中
		CarSeniorDetectViewHelper topView = (CarSeniorDetectViewHelper)uc.getAttribute(SENIOR_DETECT_INPUT_DATA);
		//根据位置跳转到不同的页面
		List<TmsDetectPic> list = (List<TmsDetectPic>)uc.getAttribute(IMGLIST);
		if(list!=null)
		{
			//将list中图片信息set到viewhelp中
			for(int i=0;i<list.size();i++)
			{
				TmsDetectPic entity = (TmsDetectPic)list.get(i);
				//从这里获取图片信息放到viewhelp中
				if(entity.getImgKey().equals("1"))
				{
					view.setImg1(entity.getImgPath());
				}
				if(entity.getImgKey().equals("2"))
				{
					view.setImg2(entity.getImgPath());
				}
				if(entity.getImgKey().equals("3"))
				{
					view.setImg3(entity.getImgPath());
				}
				if(entity.getImgKey().equals("4"))
				{
					view.setImg4(entity.getImgPath());
				}
				if(entity.getImgKey().equals("5"))
				{
					view.setImg5(entity.getImgPath());
				}
				if(entity.getImgKey().equals("6"))
				{
					view.setImg6(entity.getImgPath());
				}
				if(entity.getImgKey().equals("7"))
				{
					view.setImg7(entity.getImgPath());
				}
				if(entity.getImgKey().equals("8"))
				{
					view.setImg8(entity.getImgPath());
				}
				if(entity.getImgKey().equals("9"))
				{
					view.setImg9(entity.getImgPath());
				}
				if(entity.getImgKey().equals("10"))
				{
					view.setImg10(entity.getImgPath());
				}
				if(entity.getImgKey().equals("11"))
				{
					view.setImg11(entity.getImgPath());
				}
				if(entity.getImgKey().equals("12"))
				{
					view.setImg12(entity.getImgPath());
				}
				if(entity.getImgKey().equals("13"))
				{
					view.setImg13(entity.getImgPath());
				}
				if(entity.getImgKey().equals("14"))
				{
					view.setImg14(entity.getImgPath());
				}
				if(entity.getImgKey().equals("15"))
				{
					view.setImg15(entity.getImgPath());
				}
				if(entity.getImgKey().equals("16"))
				{
					view.setImg16(entity.getImgPath());
				}
				if(entity.getImgKey().equals("17"))
				{
					view.setImg17(entity.getImgPath());
				}
				if(entity.getImgKey().equals("18"))
				{
					view.setImg18(entity.getImgPath());
				}
				if(entity.getImgKey().equals("19"))
				{
					view.setImg19(entity.getImgPath());
				}
				if(entity.getImgKey().equals("20"))
				{
					view.setImg20(entity.getImgPath());
				}
				if(entity.getImgKey().equals("21"))
				{
					view.setImg21(entity.getImgPath());
				}
				if(entity.getImgKey().equals("22"))
				{
					view.setImg22(entity.getImgPath());
				}
				if(entity.getImgKey().equals("23"))
				{
					view.setImg23(entity.getImgPath());
				}
				if(entity.getImgKey().equals("24"))
				{
					view.setImg24(entity.getImgPath());
				}
				if(entity.getImgKey().equals("25"))
				{
					view.setImg25(entity.getImgPath());
				}
				if(entity.getImgKey().equals("26"))
				{
					view.setImg26(entity.getImgPath());
				}
				if(entity.getImgKey().equals("27"))
				{
					view.setImg27(entity.getImgPath());
				}
				if(entity.getImgKey().equals("28"))
				{
					view.setImg28(entity.getImgPath());
				}
				if(entity.getImgKey().equals("29"))
				{
					view.setImg29(entity.getImgPath());
				}
				if(entity.getImgKey().equals("30"))
				{
					view.setImg30(entity.getImgPath());
				}
				if(entity.getImgKey().equals("31"))
				{
					view.setImg31(entity.getImgPath());
				}
				if(entity.getImgKey().equals("32"))
				{
					view.setImg32(entity.getImgPath());
				}
				if(entity.getImgKey().equals("33"))
				{
					view.setImg33(entity.getImgPath());
				}
				if(entity.getImgKey().equals("34"))
				{
					view.setImg34(entity.getImgPath());
				}
			}
		}else
		{
			view.setImg1("");
			view.setImg2("");
			view.setImg3("");
			view.setImg4("");
			view.setImg5("");
			view.setImg6("");
			view.setImg7("");
			view.setImg8("");
			view.setImg9("");
			view.setImg10("");
			view.setImg11("");
			view.setImg12("");
			view.setImg13("");
			view.setImg14("");
			view.setImg15("");
			view.setImg16("");
			view.setImg17("");
			view.setImg18("");
			view.setImg19("");
			view.setImg20("");
			view.setImg21("");
			view.setImg22("");
			view.setImg23("");
			view.setImg24("");
			view.setImg25("");
			view.setImg26("");
			view.setImg27("");
			view.setImg28("");
			view.setImg29("");
			view.setImg30("");
			view.setImg31("");
			view.setImg32("");
			view.setImg33("");
			view.setImg34("");
		}
		
		
		
		
		if(position.equals("1"))
		{
			// 事故检测
			view.setBodyChk1(StringUtil.subStrTool(topView.getBodyChk1()));
			view.setBodyChk2(StringUtil.subStrTool(topView.getBodyChk2()));
			view.setBodyChk3(StringUtil.subStrTool(topView.getBodyChk3()));
			view.setBodyChk4(StringUtil.subStrTool(topView.getBodyChk4()));
			view.setBodyChk5(StringUtil.subStrTool(topView.getBodyChk5()));
			view.setBodyChk6(StringUtil.subStrTool(topView.getBodyChk6()));
			view.setBodyChk7(StringUtil.subStrTool(topView.getBodyChk7()));
			view.setBodyChk8(StringUtil.subStrTool(topView.getBodyChk8()));
			view.setBodyChk9(StringUtil.subStrTool(topView.getBodyChk9()));
			view.setBodyChk10(StringUtil.subStrTool(topView.getBodyChk10()));
			view.setBodyChk11(StringUtil.subStrTool(topView.getBodyChk11()));
			view.setBodyChk12(StringUtil.subStrTool(topView.getBodyChk12()));
			view.setBodyChk13(StringUtil.subStrTool(topView.getBodyChk13()));
			
			uc.removeAttribute(DETECT_POSITION);
			actionForward = "position1";
			uc.setAttribute(DETECT_POSITION, "1");
			
		}
		if(position.equals("2"))
		{
			//技术检测 - 车身外观录入
			view.setOutwardChkS1(StringUtil.subStrTool(topView.getOutwardChk1()));
			view.setOutwardChkS2(StringUtil.subStrTool(topView.getOutwardChk2()));
			view.setOutwardChkS3(StringUtil.subStrTool(topView.getOutwardChk3()));
			view.setOutwardChkS4(StringUtil.subStrTool(topView.getOutwardChk4()));
			view.setOutwardChkS5(StringUtil.subStrTool(topView.getOutwardChk5()));
			view.setOutwardChkS6(StringUtil.subStrTool(topView.getOutwardChk6()));
			view.setOutwardChkS7(StringUtil.subStrTool(topView.getOutwardChk7()));
			view.setOutwardChkS8(StringUtil.subStrTool(topView.getOutwardChk8()));
			view.setOutwardChkS9(StringUtil.subStrTool(topView.getOutwardChk9()));
			view.setOutwardChkS10(StringUtil.subStrTool(topView.getOutwardChk10()));
			view.setOutwardChkS11(StringUtil.subStrTool(topView.getOutwardChk11()));
			view.setOutwardChkS12(StringUtil.subStrTool(topView.getOutwardChk12()));
			view.setOutwardChkS13(StringUtil.subStrTool(topView.getOutwardChk13()));
			view.setOutwardChkS14(StringUtil.subStrTool(topView.getOutwardChk14()));
			view.setOutwardChkS15(StringUtil.subStrTool(topView.getOutwardChk15()));
			view.setOutwardChkS16(StringUtil.subStrTool(topView.getOutwardChk16()));
			view.setOutwardChkS17(StringUtil.subStrTool(topView.getOutwardChk17()));
			view.setOutwardChkS18(StringUtil.subStrTool(topView.getOutwardChk18()));
			view.setOutwardChkS19(StringUtil.subStrTool(topView.getOutwardChk19()));
			view.setOutwardChkS20(StringUtil.subStrTool(topView.getOutwardChk20()));
			view.setOutwardChkS21(StringUtil.subStrTool(topView.getOutwardChk21()));
			view.setOutwardChkS22(StringUtil.subStrTool(topView.getOutwardChk22()));
			view.setOutwardChkS23(StringUtil.subStrTool(topView.getOutwardChk23()));
			view.setOutwardChkS24(StringUtil.subStrTool(topView.getOutwardChk24()));
			view.setOutwardChkS25(StringUtil.subStrTool(topView.getOutwardChk25()));
			view.setOutwardChkS26(StringUtil.subStrTool(topView.getOutwardChk26()));

			view.setOutwardChkC1(StringUtil.subStrTool2(topView.getOutwardChk1()));
			view.setOutwardChkC2(StringUtil.subStrTool2(topView.getOutwardChk2()));
			view.setOutwardChkC3(StringUtil.subStrTool2(topView.getOutwardChk3()));
			view.setOutwardChkC4(StringUtil.subStrTool2(topView.getOutwardChk4()));
			view.setOutwardChkC5(StringUtil.subStrTool2(topView.getOutwardChk5()));
			view.setOutwardChkC6(StringUtil.subStrTool2(topView.getOutwardChk6()));
			view.setOutwardChkC7(StringUtil.subStrTool2(topView.getOutwardChk7()));
			view.setOutwardChkC8(StringUtil.subStrTool2(topView.getOutwardChk8()));
			view.setOutwardChkC9(StringUtil.subStrTool2(topView.getOutwardChk9()));
			view.setOutwardChkC10(StringUtil.subStrTool2(topView.getOutwardChk10()));
			view.setOutwardChkC11(StringUtil.subStrTool2(topView.getOutwardChk11()));
			view.setOutwardChkC12(StringUtil.subStrTool2(topView.getOutwardChk12()));
			view.setOutwardChkC13(StringUtil.subStrTool2(topView.getOutwardChk13()));
			view.setOutwardChkC14(StringUtil.subStrTool2(topView.getOutwardChk14()));
			view.setOutwardChkC15(StringUtil.subStrTool2(topView.getOutwardChk15()));
			view.setOutwardChkC16(StringUtil.subStrTool2(topView.getOutwardChk16()));
			view.setOutwardChkC17(StringUtil.subStrTool2(topView.getOutwardChk17()));
			view.setOutwardChkC18(StringUtil.subStrTool2(topView.getOutwardChk18()));
			view.setOutwardChkC19(StringUtil.subStrTool2(topView.getOutwardChk19()));
			view.setOutwardChkC20(StringUtil.subStrTool2(topView.getOutwardChk20()));
			view.setOutwardChkC21(StringUtil.subStrTool2(topView.getOutwardChk21()));
			view.setOutwardChkC22(StringUtil.subStrTool2(topView.getOutwardChk22()));
			view.setOutwardChkC23(StringUtil.subStrTool2(topView.getOutwardChk23()));
			view.setOutwardChkC24(StringUtil.subStrTool2(topView.getOutwardChk24()));
			view.setOutwardChkC25(StringUtil.subStrTool2(topView.getOutwardChk25()));
			view.setOutwardChkC26(StringUtil.subStrTool2(topView.getOutwardChk26()));
			
			uc.removeAttribute(DETECT_POSITION);
			actionForward = "position2";
			uc.setAttribute(DETECT_POSITION, "2");
		}
		if(position.equals("3"))
		{
			//技术检测 - 发动机舱录入
			view.setEngineChk1(topView.getEngineChk1());
			view.setEngineChk2(topView.getEngineChk2());
			view.setEngineChk3(topView.getEngineChk3());
			view.setEngineChk4(topView.getEngineChk4());
			view.setEngineChk5(topView.getEngineChk5());
			view.setEngineChk6(topView.getEngineChk6());
			view.setEngineChk7(topView.getEngineChk7());
			view.setEngineChk8(topView.getEngineChk8());
			view.setEngineChk9(topView.getEngineChk9());
			
			uc.removeAttribute(DETECT_POSITION);
			actionForward = "position3";
			uc.setAttribute(DETECT_POSITION, "3");
		}
		if(position.equals("4"))
		{
			// 技术检测 - 驾驶舱录入
			view.setPilotChk1(topView.getPilotChk1());
			view.setPilotChk2(topView.getPilotChk2());
			view.setPilotChk3(topView.getPilotChk3());
			view.setPilotChk4(topView.getPilotChk4());
			view.setPilotChk5(topView.getPilotChk5());
			view.setPilotChk6(topView.getPilotChk6());
			view.setPilotChk7(topView.getPilotChk7());
			view.setPilotChk8(topView.getPilotChk8());
			view.setPilotChk9(topView.getPilotChk9());
			view.setPilotChk10(topView.getPilotChk10());
			view.setPilotChk11(topView.getPilotChk11());
			view.setPilotChk12(topView.getPilotChk12());
			view.setPilotChk13(topView.getPilotChk13());
			view.setPilotChk14(topView.getPilotChk14());
			
			uc.removeAttribute(DETECT_POSITION);
			actionForward = "position4";
			uc.setAttribute(DETECT_POSITION, "4");
		}
		if(position.equals("5"))
		{
			// 技术检测 - 启动录入
			view.setStartChk1(topView.getStartChk1());
			view.setStartChk2(topView.getStartChk2());
			view.setStartChk3(topView.getStartChk3());
			view.setStartChk4(topView.getStartChk4());
			view.setStartChk5(topView.getStartChk5());
			view.setStartChk6(topView.getStartChk6());
			view.setStartChk7(topView.getStartChk7());
			view.setStartChk8(topView.getStartChk8());
			view.setStartChk9(topView.getStartChk9());
			
			uc.removeAttribute(DETECT_POSITION);
			actionForward = "position5";
			uc.setAttribute(DETECT_POSITION, "5");
		}
		if(position.equals("6"))
		{
			// 技术检测 - 路试录入
			view.setRunChk1(topView.getRunChk1());
			view.setRunChk2(topView.getRunChk2());
			view.setRunChk3(topView.getRunChk3());
			view.setRunChk4(topView.getRunChk4());
			view.setRunChk5(topView.getRunChk5());
			view.setRunChk6(topView.getRunChk6());
			view.setRunChk7(topView.getRunChk7());
			view.setRunChk8(topView.getRunChk8());
			view.setRunChk9(topView.getRunChk9());
			
			uc.removeAttribute(DETECT_POSITION);
			actionForward = "position6";
			uc.setAttribute(DETECT_POSITION, "6");
		}
		if(position.equals("7"))
		{
			// 技术检测 - 底盘录入
			view.setBottomChk1(topView.getBottomChk1());
			view.setBottomChk2(topView.getBottomChk2());
			view.setBottomChk3(topView.getBottomChk3());
			view.setBottomChk4(topView.getBottomChk4());
			view.setBottomChk5(topView.getBottomChk5());
			view.setBottomChk6(topView.getBottomChk6());
			view.setBottomChk7(topView.getBottomChk7());
			
			uc.removeAttribute(DETECT_POSITION);
			actionForward = "position7";
			uc.setAttribute(DETECT_POSITION, "7");
		}
		if(position.equals("8"))
		{
			// 检测说明录入
			view.setCarDescribe(topView.getCarDescribe());
			
			uc.removeAttribute(DETECT_POSITION);
			actionForward = "position8";
			uc.setAttribute(DETECT_POSITION, "8");
		}
		
		
		//将上个页面的车辆ID获取重set到viewhelp中
//		String carSerial = (String)uc.getAttribute(CARSERIAL);
		//向viewhelp中set列表list 包括缺陷程度描述和评分 从字典表中取得
		DectCodes code = DectCodes.getInstance();
		//这个需要加在另一个viewhelp中每次打开的 时候需要将页面的值带出来
		view.setSeniorDectSList(code.getCodeslistByItemId(DectCodes.SENIOR_CARDECT_ACCIDENT_CHECK));//高级检测  缺陷描述下拉列表
		view.setSeniorDectCList(code.getCodeslistByItemId(DectCodes.SENIOR_CARDECT_LEVEL));//高级检测 缺陷程度下拉列表
		
		request.setAttribute(TmsConstants.VIEWHELP, view);
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(actionForward);
	}

}
